package sanshui.system.trade.factory.trade.worker;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sanshui.system.trade.common.GlobalContain;
import sanshui.system.trade.factory.data.DataCache;
import sanshui.system.trade.factory.data.TradeSystemType;
import sanshui.system.trade.factory.notify.TradeSysNotifyModel;
import sanshui.system.trade.factory.trade.TradeSystemContext;
import sanshui.system.trade.factory.trade.strategy.StrategyResult;
import sanshui.system.trade.factory.trade.strategy.TradeStrategy;
import sanshui.system.trade.model.NotifyModel;
import sanshui.system.trade.model.TradeSysWorkerModel;
import sanshui.system.trade.util.CommonTimeUtil;

import java.time.LocalDateTime;
import java.util.List;

public abstract class BackTradeWorker extends AbstractTradeWorker {
    private static final Logger logger = LoggerFactory.getLogger(BackTradeWorker.class);


    public BackTradeWorker(TradeSysWorkerModel tradeModel, DataCache dataCache) {
        super(tradeModel, dataCache);
    }

    protected abstract boolean isValidInThisAccountUseCache(List<StrategyResult> endStrategyCalls) throws Exception;

    @Override
    protected void notifyInfo(TradeSystemContext context, GlobalContain.NotifyType notifyType) {
        super.notifyInfo(context, notifyType);

    }
    protected void updateAccountToCacheInRt(){
        return;
    }

    @Override
    protected boolean needWaitData(LocalDateTime currentTime) throws Exception {
        return false;
    }

    @Override
    protected boolean continueTradeClear(LocalDateTime currentTime, DataCache dataCache) {
        if (null == currentTime) {
            // 清除历史数据, 清理空间
            dataCache.clear();
            logger.debug("交易中历史数据已经用完了, 停止, endTime:{}, now:{}", CommonTimeUtil.getNowTime16(currentTime), CommonTimeUtil.getNowTime16(LocalDateTime.now()));
            return false;
        }
        return true;
    }
}
